<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="baidu-site-verification" content="zD47G9xe42" />


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="uiste个人博客网站,uiste,uiste博客,PHP,运维,Hexo,技术博客" />





  <link rel="alternate" href="/atom.xml" title="uiste" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="Stay Hungry，Stay Foolish">
<meta property="og:type" content="website">
<meta property="og:title" content="uiste">
<meta property="og:url" content="http://blog.uiste.com/page/7/index.html">
<meta property="og:site_name" content="uiste">
<meta property="og:description" content="Stay Hungry，Stay Foolish">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="uiste">
<meta name="twitter:description" content="Stay Hungry，Stay Foolish">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://blog.uiste.com/page/7/"/>

  <title>
 
  uiste - Stay Hungry，Stay Foolish 

</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?b58b87af012832b8ae35e33bb45b44fa";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">uiste</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">uiste个人博客</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      

            <li class="menu-item menu-item-search"> <a title="把这个链接拖到你的Chrome收藏夹工具栏中" href='javascript:(function() {
    function c() {
        var e = document.createElement("link");
        e.setAttribute("type", "text/css");
        e.setAttribute("rel", "stylesheet");
        e.setAttribute("href", f);
        e.setAttribute("class", l);
        document.body.appendChild(e)
    }
 
    function h() {
        var e = document.getElementsByClassName(l);
        for (var t = 0; t < e.length; t++) {
            document.body.removeChild(e[t])
        }
    }
 
    function p() {
        var e = document.createElement("div");
        e.setAttribute("class", a);
        document.body.appendChild(e);
        setTimeout(function() {
            document.body.removeChild(e)
        }, 100)
    }
 
    function d(e) {
        return {
            height : e.offsetHeight,
            width : e.offsetWidth
        }
    }
 
    function v(i) {
        var s = d(i);
        return s.height > e && s.height < n && s.width > t && s.width < r
    }
 
    function m(e) {
        var t = e;
        var n = 0;
        while (!!t) {
            n += t.offsetTop;
            t = t.offsetParent
        }
        return n
    }
 
    function g() {
        var e = document.documentElement;
        if (!!window.innerWidth) {
            return window.innerHeight
        } else if (e && !isNaN(e.clientHeight)) {
            return e.clientHeight
        }
        return 0
    }
 
    function y() {
        if (window.pageYOffset) {
            return window.pageYOffset
        }
        return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
    }
 
    function E(e) {
        var t = m(e);
        return t >= w && t <= b + w
    }
 
    function S() {
        var e = document.createElement("audio");
        e.setAttribute("class", l);
        e.src = i;
        e.loop = false;
        e.addEventListener("canplay", function() {
            setTimeout(function() {
                x(k)
            }, 500);
            setTimeout(function() {
                N();
                p();
                for (var e = 0; e < O.length; e++) {
                    T(O[e])
                }
            }, 15500)
        }, true);
        e.addEventListener("ended", function() {
            N();
            h()
        }, true);
        e.innerHTML = " <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>";
        document.body.appendChild(e);
        e.play()
    }
 
    function x(e) {
        e.className += " " + s + " " + o
    }
 
    function T(e) {
        e.className += " " + s + " " + u[Math.floor(Math.random() * u.length)]
    }
 
    function N() {
        var e = document.getElementsByClassName(s);
        var t = new RegExp("\\b" + s + "\\b");
        for (var n = 0; n < e.length; ) {
            e[n].className = e[n].className.replace(t, "")
        }
    }
 
    var e = 30;
    var t = 30;
    var n = 350;
    var r = 350;
    var i = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake.mp3";
    var s = "mw-harlem_shake_me";
    var o = "im_first";
    var u = ["im_drunk", "im_baked", "im_trippin", "im_blown"];
    var a = "mw-strobe_light";
    var f = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css";
    var l = "mw_added_css";
    var b = g();
    var w = y();
    var C = document.getElementsByTagName("*");
    var k = null;
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            if (E(A)) {
                k = A;
                break
            }
        }
    }
    if (A === null) {
        console.warn("Could not find a node of the right size. Please try a different page.");
        return
    }
    c();
    S();
    var O = [];
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            O.push(A)
        }
    }
})()    '>High</a> </li>

    </ul>
  

 
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
   
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160910-Library-php-note.html" itemprop="url">
                  PHP - MySQL SQL注入
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-10T09:26:25+08:00" content="2016-09-10">
              2016-09-10
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160910-Library-php-note.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160910-Library-php-note.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="SQL-注入"><a href="#SQL-注入" class="headerlink" title="SQL 注入"></a>SQL 注入</h1><p>用户名注入：<br><code>select * from admin where name=&#39;&#39; or 1=1 or &#39;&#39; and pwd = &#39;&#39;;</code><br><code>select * from admin where name=&#39;&#39; or 1=1 # &#39;&#39; and pwd = &#39;&#39;;</code><br><code>select * from admin where name=&#39;&#39; or 1=1 -- &#39;&#39; and pwd = &#39;&#39;;</code></p>
<blockquote>
<p>‘ or 1=1 or ‘’<br>‘ or 1=1 # ‘’<br>‘ or 1=1 – ‘’</p>
</blockquote>
<p>密码注入：<br><code>select * from admin where name=&#39;&#39; and pwd = &#39;&#39; OR &#39;&#39;=&#39;&#39;;</code></p>
<blockquote>
<p>‘ OR ‘’=’</p>
</blockquote>
<p>解决方法一：<br><code>mysql_real_escape_string()</code> 函数转义 SQL 语句中使用的字符串中的特殊字符。<br>下列字符受影响：<br><code>\x00</code><br><code>\n</code><br><code>\r</code><br><code>\</code><br><code>&#39;</code><br><code>&quot;</code><br><code>\x1a</code><br>如果成功，则该函数返回被转义的字符串。如果失败，则返回 false。<br>语法<br><code>mysql_real_escape_string(string,connection)</code><br>| 参数 | 描述 |<br>| — | — |<br>| string<span class="Apple-tab-span" style="white-space:pre"></span> | 必需。规定要转义的字符串。 |<br>| connection | 可选。规定 MySQL 连接。如果未规定，则使用上一个连接。 |</p>
<p>解决方法二：<code>string mysql_escape_string ( string $unescaped_string )</code></p>
<blockquote>
<p><code>mysql_escape_string()</code> 并不转义 <code>%</code> 和 <code>_</code>。 本函数和 <code>mysql_real_escape_string()</code> 完全一样，除了 <code>mysql_real_escape_string()</code> 接受的是一个连接句柄并根据当前字符集转移字符串之外。<code>mysql_escape_string()</code> 并不接受连接参数，也不管当前字符集设定。</p>
</blockquote>
<p>解决方法三：<br><code>string addslashes ( string $str )</code><br>返回字符串，该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号（’）、双引号（”）、反斜线（\）与 NUL（NULL 字符）。</p>
<p>解决方法四：<br>面向对象风格<br><code>string mysqli::escape_string ( string $escapestr )</code><br><code>string mysqli::real_escape_string ( string $escapestr )</code></p>
<p>过程化风格<br><code>string mysqli_real_escape_string ( mysqli $link , string $escapestr )</code></p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160909-1.html" itemprop="url">
                  PHP-http协议请求、防盗链
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-09T19:28:00+08:00" content="2016-09-09">
              2016-09-09
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160909-1.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160909-1.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>HyperText Transfer Protocol  超文本传输协议（文本、图片、视频等）<br>http 是建立在 TCP/IP协议的一个应用层协议</p>
<p>内容一样浏览器只发出1次http请求！</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">请求行：GET /js.php HTTP/1.1 【请求资源-协议版本】</div><div class="line">消息头：</div><div class="line">Host: www.test.com  【主机】</div><div class="line">User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0   【告诉服务器浏览器的内核、操作系统】</div><div class="line">Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  【客户端可以接受的文件类型】</div><div class="line">Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3  【网页语言】</div><div class="line">Accept-Encoding: gzip, deflate   【接收什么样的数据压缩格式】</div><div class="line">Referer: http://www.test.com/     【代表页面是从哪儿来的】</div><div class="line">Connection: keep-alive   【表示不要立即断掉】</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">响应头信息</div><div class="line">HTTP/1.1 200 OK   【200 OK 表示客户端请求成功】</div><div class="line">Date: Fri, 09 Sep 2016 08:52:49 GMT  【告诉浏览器请求页面的时间】</div><div class="line">Server: Apache/2.4.7 (Unix) PHP/5.5.9 OpenSSL/1.0.1f mod_perl/2.0.8-dev Perl/v5.16.3  【告诉浏览器服务的情况】</div><div class="line">X-Powered-By: PHP/5.5.9  </div><div class="line">Content-Length: 1331  【表示或送的数据有多少字节】</div><div class="line">Keep-Alive: timeout=5, max=100</div><div class="line">Connection: Keep-Alive</div><div class="line">Content-Type: text/html   【文档类型】</div></pre></td></tr></table></figure>
<blockquote>
<p>Date：告诉浏览器，请求页面的时间！（用于判断页面相应时间，根据时间反应是否可以调用缓存信息）</p>
</blockquote>
<p>一个空行：<br>消息体（实体内容）<br>xxx</p>
<h3 id="SERVER-服务器和执行环境信息"><a href="#SERVER-服务器和执行环境信息" class="headerlink" title="$_SERVER 服务器和执行环境信息"></a>$_SERVER 服务器和执行环境信息</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div></pre></td><td class="code"><pre><div class="line">Array</div><div class="line">(</div><div class="line">    [UNIQUE_ID] =&gt; V9J4YX8AAAEAAPozd4EAAAAC</div><div class="line">    [HTTP_HOST] =&gt; www.test.com</div><div class="line">    [HTTP_USER_AGENT] =&gt; Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0</div><div class="line">    [HTTP_ACCEPT] =&gt; text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</div><div class="line">    [HTTP_ACCEPT_LANGUAGE] =&gt; zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3</div><div class="line">    [HTTP_ACCEPT_ENCODING] =&gt; gzip, deflate</div><div class="line">    [HTTP_CONNECTION] =&gt; keep-alive</div><div class="line">    [PATH] =&gt; /usr/bin:/bin:/usr/sbin:/sbin</div><div class="line">    [DYLD_LIBRARY_PATH] =&gt; /Applications/XAMPP/xamppfiles/lib</div><div class="line">    [SERVER_SIGNATURE] =&gt; </div><div class="line">    [SERVER_SOFTWARE] =&gt; Apache/2.4.7 (Unix) PHP/5.5.9 OpenSSL/1.0.1f mod_perl/2.0.8-dev Perl/v5.16.3</div><div class="line">    [SERVER_NAME] =&gt; www.test.com</div><div class="line">    [SERVER_ADDR] =&gt; 127.0.0.1</div><div class="line">    [SERVER_PORT] =&gt; 80</div><div class="line">    [REMOTE_ADDR] =&gt; 127.0.0.1</div><div class="line">    [DOCUMENT_ROOT] =&gt; /Users/uiste/www/</div><div class="line">    [REQUEST_SCHEME] =&gt; http</div><div class="line">    [CONTEXT_PREFIX] =&gt; </div><div class="line">    [CONTEXT_DOCUMENT_ROOT] =&gt; /Users/uiste/www/</div><div class="line">    [SERVER_ADMIN] =&gt; you@example.com</div><div class="line">    [SCRIPT_FILENAME] =&gt; /Users/uiste/www/test.php</div><div class="line">    [REMOTE_PORT] =&gt; 50802</div><div class="line">    [GATEWAY_INTERFACE] =&gt; CGI/1.1</div><div class="line">    [SERVER_PROTOCOL] =&gt; HTTP/1.1</div><div class="line">    [REQUEST_METHOD] =&gt; GET</div><div class="line">    [QUERY_STRING] =&gt; </div><div class="line">    [REQUEST_URI] =&gt; /test.php</div><div class="line">    [SCRIPT_NAME] =&gt; /test.php</div><div class="line">    [PHP_SELF] =&gt; /test.php</div><div class="line">    [REQUEST_TIME_FLOAT] =&gt; 1473411169.446</div><div class="line">    [REQUEST_TIME] =&gt; 1473411169</div><div class="line">)</div></pre></td></tr></table></figure>
<p>【PATH】：服务器端的环境变量<br>$_SERVER[‘REMOTE_ADDR’] 获取本地的IP地址；<br>REQUEST_URI  获取请求的资源名</p>
<p>DOCUMENT_ROOT 站点根目录</p>
<h3 id="Referer-：防盗链"><a href="#Referer-：防盗链" class="headerlink" title="Referer ：防盗链"></a>Referer ：防盗链</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">if (isset($_SERVER[&apos;HTTP_REFERER&apos;])) &#123;</div><div class="line">	if (strpos($_SERVER[&apos;SERVER_ADDR&apos;],$_SERVER[&apos;HTTP_REFERER&apos;])===0) &#123;</div><div class="line">		echo &apos;您是合法用户&apos;;</div><div class="line">	&#125;else&#123;</div><div class="line">		echo &quot;您是非法用户&quot;;</div><div class="line">	&#125;</div><div class="line">&#125;else&#123;</div><div class="line">	echo &quot;你这用户不合法&quot;;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<blockquote>
<p>注意字符串查找返回0，0与false的比较问题</p>
</blockquote>
<h3 id="http请求有两种主要的方式"><a href="#http请求有两种主要的方式" class="headerlink" title="http请求有两种主要的方式"></a>http请求有两种主要的方式</h3><p>get/post<br>相同：都是向服务器发送数据<br>区别：<br>1、安全性get请求的数据会显示在地址栏上，post请求的数据，放在http协议的消息体上<br>2、http协议本身并没有限制数据的大小，主要是浏览器限制get请求2k+35<br>    对post请求没有限制<br>3、get提交的更利于添加到收藏夹</p>
<h3 id="状态码"><a href="#状态码" class="headerlink" title="状态码"></a>状态码</h3><p>状态码-含义<br>100~199：表示成功接收请求，要求客户端继续提交下一次请求才能完成整个处理过程<br>200~299：表示成功接收请求并已完成整个处理过程，常用200<br>300~399：为完成请求，客户需进一步细化请求，例如，请求的资源已经移动到一个新地址，常用302，304<br>400~499：客户端的请求有错误，常用404<br>500~599：服务器端出现错误，常用500</p>
<blockquote>
<p>302:页面重定向<br>404:该页面不存在<br>304:资源已存在</p>
</blockquote>
<p>跳转<code>header(&quot;refresh:3;url=http://www.uiste.com&quot;);</code></p>
<h3 id="通过header禁用缓存-ajax"><a href="#通过header禁用缓存-ajax" class="headerlink" title="通过header禁用缓存(ajax)"></a>通过header禁用缓存(ajax)</h3><p>header(“Expires:-1”);<br>header(“Cache-Control:noch”);<br>header(“Pragma:no-cache”);</p>
<h3 id="文件下载"><a href="#文件下载" class="headerlink" title="文件下载"></a>文件下载</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;?php</span> </div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">downfile</span><span class="params">($filename)</span></span>&#123;</div><div class="line">$filename = <span class="string">'xxx.jpg'</span>;</div><div class="line"><span class="comment">//中文转码</span></div><div class="line">$filename = iconv(<span class="string">'utf-8'</span>,<span class="string">'gb2312'</span>,$filename);</div><div class="line"><span class="comment">//绝对路径</span></div><div class="line">$filepath = $_SERVER[<span class="string">'DOCUMENT_ROOT'</span>].<span class="string">'down/'</span>.$filename;</div><div class="line"><span class="comment">//打开文件</span></div><div class="line"><span class="keyword">if</span> (!file_exists($filepath)) &#123;</div><div class="line">	<span class="keyword">echo</span> <span class="string">'文件不存在'</span>;</div><div class="line">	<span class="keyword">return</span>;</div><div class="line">&#125;</div><div class="line">$fp=fopen($filename,<span class="string">'r'</span>);</div><div class="line"><span class="comment">//获取下载文件的大小</span></div><div class="line">$filesize = filesize($filepath);</div><div class="line"><span class="comment">//返回的文件</span></div><div class="line">header(<span class="string">"Content-Type:application/octet-stream"</span>);</div><div class="line"><span class="comment">//按照字节大小返回</span></div><div class="line">header(<span class="string">"Accept-Ranges:bytes"</span>);</div><div class="line"><span class="comment">//返回文件大小</span></div><div class="line">header(<span class="string">"Accept-Length:$filesize"</span>);</div><div class="line"><span class="comment">//客户端弹出对话框，对应的文件名</span></div><div class="line">header(<span class="string">"Content-Disposition:attachment;filename="</span>.$filename);</div><div class="line"><span class="comment">//先客户端回送数据</span></div><div class="line">$buffer = <span class="number">1024</span>;</div><div class="line"><span class="comment">//读取文件</span></div><div class="line">$filedata = fread($fp,$buffer);</div><div class="line"><span class="comment">//关闭文件</span></div><div class="line">fclose($fp);</div><div class="line">&#125;</div><div class="line"><span class="meta">?&gt;</span></div></pre></td></tr></table></figure>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160907-1.html" itemprop="url">
                  PHP-错误处理、异常处理
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-07T19:33:15+08:00" content="2016-09-07">
              2016-09-07
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160907-1.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160907-1.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="die-的应用"><a href="#die-的应用" class="headerlink" title="die 的应用"></a>die 的应用</h3><p>方式一：<br>if(条件){<br>    die(‘错误信息’);<br>}<br>方式二：<br>执行语句 or die(‘错误信息’);</p>
<h3 id="错误函数（处理器）"><a href="#错误函数（处理器）" class="headerlink" title="错误函数（处理器）"></a>错误函数（处理器）</h3><p>自定义错误处理方式</p>
<h4 id="创建自定义错误处理器"><a href="#创建自定义错误处理器" class="headerlink" title="创建自定义错误处理器"></a>创建自定义错误处理器</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">function customError($errno, $errstr)</div><div class="line"> &#123; </div><div class="line"> echo &quot;&lt;b&gt;Error:&lt;/b&gt; [$errno] $errstr&lt;br /&gt;&quot;;</div><div class="line"> echo &quot;Ending Script&quot;;</div><div class="line"> die();</div><div class="line"> &#125;</div></pre></td></tr></table></figure>
<h4 id="Set-Error-Handler"><a href="#Set-Error-Handler" class="headerlink" title="Set Error Handler"></a>Set Error Handler</h4><p><code>set_error_handler(&quot;customError&quot;);</code></p>
<h4 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">&lt;?php</div><div class="line">//error handler function</div><div class="line">function customError($errno, $errstr)</div><div class="line"> &#123; </div><div class="line"> echo &quot;&lt;b&gt;Error:&lt;/b&gt; [$errno] $errstr&quot;;</div><div class="line"> &#125;</div><div class="line"></div><div class="line">//set error handler</div><div class="line">set_error_handler(&quot;customError&quot;);</div><div class="line"></div><div class="line">//trigger error</div><div class="line">echo($test);</div><div class="line">?&gt;</div><div class="line">以上代码的输出应该类似这样：</div><div class="line">Error: [8] Undefined variable: test</div></pre></td></tr></table></figure>
<h3 id="错误函数（触发器）"><a href="#错误函数（触发器）" class="headerlink" title="错误函数（触发器）"></a>错误函数（触发器）</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;?php</span></div><div class="line">$age = <span class="number">700</span>;</div><div class="line"><span class="keyword">if</span> ($age&gt;<span class="number">120</span>) &#123;</div><div class="line">	trigger_error(<span class="string">'输入年龄太大'</span>,E_USER_ERROR);</div><div class="line">	<span class="keyword">exit</span>();</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="meta">?&gt;</span></div></pre></td></tr></table></figure>
<blockquote>
<p>指定报错方式</p>
</blockquote>
<h3 id="错误日志"><a href="#错误日志" class="headerlink" title="错误日志"></a>错误日志</h3><p>根据php.ini中的error_log配置，PHP向服务器的错误记录系统或文件发送错误记录。通过使用error_log()函数，用户可以向指定的文件或远程目的地发送错误记录</p>
<p>``bool error_log (string $message [,int$message_type=0[,string $destination [,string $extra_headers]]])</p>
<h3 id="预定义异常"><a href="#预定义异常" class="headerlink" title="预定义异常"></a>预定义异常</h3><p>exception</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160905-2.html" itemprop="url">
                  PHP、终端-模拟get请求
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-05T16:57:44+08:00" content="2016-09-05">
              2016-09-05
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160905-2.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160905-2.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="Mac-设置文件夹权限为777"><a href="#Mac-设置文件夹权限为777" class="headerlink" title="Mac 设置文件夹权限为777"></a>Mac 设置文件夹权限为777</h3><blockquote>
<p>1.cd 你的文件夹路径的上一级目录。<br>2.<code>sudo chmod -R 777 文件夹名</code><br>3.输入密码<br>4.成功</p>
</blockquote>
<p>fsockopen(‘主机’,’端口号’,’错误号’,’错误描述’，’连接时限’);</p>
<h3 id="使用命令行模拟get请求"><a href="#使用命令行模拟get请求" class="headerlink" title="使用命令行模拟get请求"></a>使用命令行模拟get请求</h3><ul>
<li><p>telnet www.test.com 80</p>
</li>
<li><p>ctrl + ]</p>
</li>
<li><p>enter</p>
</li>
<li><p>GET /httpget.php HTTP/1.1</p>
</li>
<li><p>Host: www.test.com</p>
</li>
</ul>
<h3 id="使用PHP模拟get请求"><a href="#使用PHP模拟get请求" class="headerlink" title="使用PHP模拟get请求"></a>使用PHP模拟get请求</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">header(&apos;content-type:text/html;charset=utf8&apos;);</div><div class="line">$fp = fsockopen(&apos;www.test.com&apos;,80,$errno,$error,3);</div><div class="line">if (!$fp) &#123;</div><div class="line">	// 主机或者端口等定义内容写错了就会报错</div><div class="line">	echo &apos;错误号&apos;.$errno.&apos;&lt;br&gt;&apos;;</div><div class="line">	echo &apos;错误描述&apos;.$error.&apos;&lt;br&gt;&apos;;</div><div class="line">&#125;</div><div class="line">$str = &apos;GET /httpget.php HTTP/1.1&apos;.PHP_EOL;</div><div class="line">$str.= &apos;Host: www.test.com&apos;.PHP_EOL;</div><div class="line">$str.= PHP_EOL;</div><div class="line"></div><div class="line">// 向打开的连接资源中写入数据，就是get请求数据</div><div class="line">fwrite($fp,$str);</div><div class="line">// 读取数据</div><div class="line">while (!feof($fp)) &#123;</div><div class="line">	echo fgets($fp).&apos;&lt;br&gt;&apos;;</div><div class="line">&#125;</div><div class="line"></div><div class="line">fclose($fp);</div><div class="line">?&gt;</div></pre></td></tr></table></figure>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160905-1.html" itemprop="url">
                  PHP闲来无事，小打小闹
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-05T16:28:29+08:00" content="2016-09-05">
              2016-09-05
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160905-1.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160905-1.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="文件操作"><a href="#文件操作" class="headerlink" title="文件操作"></a>文件操作</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;?php</span> </div><div class="line"><span class="keyword">if</span> (!file_exists(<span class="string">'a/b/c/d/'</span>)) &#123;</div><div class="line">	mkdir(<span class="string">'a/b/c/d'</span>,<span class="number">0777</span>,<span class="keyword">true</span>);</div><div class="line">	<span class="keyword">echo</span> <span class="string">"文件目录创建成功"</span>;</div><div class="line">&#125;<span class="keyword">elseif</span>(!file_exists(<span class="string">'a/b/c/d/aaa.txt'</span>))&#123;</div><div class="line">	$fp=fopen(<span class="string">'a/b/c/d/aaa.txt'</span>,<span class="string">'w'</span>);</div><div class="line">	fwrite($fp, <span class="string">'闲的无聊'</span>);</div><div class="line">	<span class="keyword">echo</span> <span class="string">"文件内容创建成功"</span>;</div><div class="line">&#125;<span class="keyword">elseif</span>(file_exists(<span class="string">'a/b/c/d/aaa.txt'</span>))&#123;</div><div class="line">	unlink(<span class="string">'a/b/c/d/aaa.txt'</span>);</div><div class="line">	<span class="keyword">echo</span> <span class="string">"文件内容删除成功"</span>,<span class="string">'&lt;br&gt;'</span>;</div><div class="line">	rmdir(<span class="string">'a/b/c/d'</span>);</div><div class="line">	rmdir(<span class="string">'a/b/c'</span>);</div><div class="line">	rmdir(<span class="string">'a/b'</span>);</div><div class="line">	rmdir(<span class="string">'a'</span>);</div><div class="line">	<span class="keyword">echo</span> <span class="string">"文件目录删除成功"</span>;</div><div class="line">&#125;</div><div class="line"><span class="meta">?&gt;</span></div></pre></td></tr></table></figure>
<h3 id="上传下载"><a href="#上传下载" class="headerlink" title="上传下载"></a>上传下载</h3><p>核心</p>
<blockquote>
<ol>
<li>设计表单时注意属性：<code>enctype=&quot;multipart/form-data&quot;；</code></li>
<li>文件接收时：<code>print_r ($_FILES[&#39;file&#39;]);</code>返回数组文件内容</li>
<li>判断文件是否上传成功：<code>is_uploaded_file($_FILES[&#39;file&#39;][&#39;tmp_name&#39;])</code></li>
<li>定义上传路径与保存路径</li>
<li>// 把文件转存到希望的文件目录<br><code>$upload_file = $_FILES[&#39;file&#39;][&#39;tmp_name&#39;];</code></li>
<li><code>file_exists</code>判断转移文件夹存在与否，通过<code>mkdir</code>新建转移文件夹</li>
<li>// 通过<code>time()</code>与<code>rand()</code>获取时间戳对文件重命名避免上传文件的重复而被覆盖<br><code>$move_file = $_SERVER[&#39;DOCUMENT_ROOT&#39;].&quot;upload/&quot;.time().rand(0,100).$_FILES[&#39;file&#39;][&#39;name&#39;];</code></li>
<li>文件路径转移函数<br><code>move_uploaded_file($upload_file,$move_file)</code></li>
<li>中文转码：<code>string iconv ( string $in_charset , string $out_charset , string $str );</code></li>
</ol>
</blockquote>
<p>前台页面</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">"control.php"</span> <span class="attr">method</span>=<span class="string">"post"</span> <span class="attr">enctype</span>=<span class="string">"multipart/form-data"</span>&gt;</span></div><div class="line"><span class="tag">&lt;<span class="name">table</span>&gt;</span></div><div class="line">	<span class="tag">&lt;<span class="name">tr</span>&gt;</span><span class="tag">&lt;<span class="name">td</span> <span class="attr">colspan</span>=<span class="string">"2"</span> &gt;</span><span class="tag">&lt;<span class="name">font</span> <span class="attr">style</span>=<span class="string">"font-size: 20px;"</span>&gt;</span>上传文件<span class="tag">&lt;/<span class="name">font</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span><span class="tag">&lt;/<span class="name">tr</span>&gt;</span></div><div class="line">	<span class="tag">&lt;<span class="name">tr</span>&gt;</span></div><div class="line">		<span class="tag">&lt;<span class="name">td</span>&gt;</span>文件分类<span class="tag">&lt;/<span class="name">td</span>&gt;</span></div><div class="line">		<span class="tag">&lt;<span class="name">td</span>&gt;</span></div><div class="line">			<span class="tag">&lt;<span class="name">select</span> <span class="attr">name</span>=<span class="string">"resource"</span>&gt;</span></div><div class="line">				<span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">'pic'</span>&gt;</span>图片<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">				<span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">'mus'</span>&gt;</span>音乐<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">				<span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">'vio'</span>&gt;</span>视频<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">				<span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">'doc'</span>&gt;</span>文档<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">				<span class="tag">&lt;<span class="name">option</span> <span class="attr">value</span>=<span class="string">'txt'</span>&gt;</span>文件<span class="tag">&lt;/<span class="name">option</span>&gt;</span></div><div class="line">			<span class="tag">&lt;/<span class="name">select</span>&gt;</span></div><div class="line">			<span class="tag">&lt;<span class="name">span</span> <span class="attr">style</span>=<span class="string">'font-size:6px;color:#ff9955;'</span>&gt;</span>暂时只支持上传“png”与“jpg”格式的图片资源<span class="tag">&lt;/<span class="name">span</span>&gt;</span></div><div class="line">		<span class="tag">&lt;/<span class="name">td</span>&gt;</span></div><div class="line">	<span class="tag">&lt;/<span class="name">tr</span>&gt;</span></div><div class="line">	<span class="tag">&lt;<span class="name">tr</span>&gt;</span></div><div class="line">		<span class="tag">&lt;<span class="name">td</span>&gt;</span>文件介绍<span class="tag">&lt;/<span class="name">td</span>&gt;</span></div><div class="line">		<span class="tag">&lt;<span class="name">td</span>&gt;</span><span class="tag">&lt;<span class="name">textarea</span> <span class="attr">cols</span>=<span class="string">"30"</span> <span class="attr">rows</span>=<span class="string">"10"</span> <span class="attr">name</span>=<span class="string">"describe"</span>&gt;</span><span class="tag">&lt;/<span class="name">textarea</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></div><div class="line">	<span class="tag">&lt;/<span class="name">tr</span>&gt;</span></div><div class="line">	<span class="tag">&lt;<span class="name">tr</span>&gt;</span></div><div class="line">		<span class="tag">&lt;<span class="name">td</span>&gt;</span>上传文件<span class="tag">&lt;/<span class="name">td</span>&gt;</span></div><div class="line">		<span class="tag">&lt;<span class="name">td</span>&gt;</span><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"file"</span> <span class="attr">name</span>=<span class="string">"file"</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></div><div class="line">	<span class="tag">&lt;/<span class="name">tr</span>&gt;</span></div><div class="line">	<span class="tag">&lt;<span class="name">tr</span>&gt;</span></div><div class="line">		<span class="tag">&lt;<span class="name">td</span>&gt;</span>点击提交<span class="tag">&lt;/<span class="name">td</span>&gt;</span></div><div class="line">		<span class="tag">&lt;<span class="name">td</span>&gt;</span><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"submit"</span> <span class="attr">name</span>=<span class="string">"btn"</span>&gt;</span><span class="tag">&lt;/<span class="name">td</span>&gt;</span></div><div class="line">	<span class="tag">&lt;/<span class="name">tr</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">table</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">form</span>&gt;</span></div></pre></td></tr></table></figure>
<p>控制器</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;?php</span> </div><div class="line"><span class="keyword">require</span> $_SERVER[<span class="string">'DOCUMENT_ROOT'</span>].<span class="string">'inc/conn.php'</span>;</div><div class="line"><span class="comment">// 判断是否提交数据</span></div><div class="line"><span class="keyword">if</span> ($_POST[<span class="string">'btn'</span>]) &#123;</div><div class="line">	<span class="comment">// 接收提交内容</span></div><div class="line">	$resource = $_POST[<span class="string">'resource'</span>];</div><div class="line">	$describe = $_POST[<span class="string">'describe'</span>];</div><div class="line">	<span class="comment">// 显示FILES全局变量的信息</span></div><div class="line">	<span class="comment">// echo "&lt;pre&gt;";</span></div><div class="line">	<span class="comment">// print_r ($_FILES['file']);</span></div><div class="line">	<span class="comment">// echo "&lt;/pre&gt;";</span></div><div class="line"></div><div class="line">	<span class="comment">//判断文件大小，限制在10M以内</span></div><div class="line">	<span class="keyword">if</span> ($_FILES[<span class="string">'file'</span>][<span class="string">'size'</span>]&gt;<span class="number">10</span>*<span class="number">1024</span>*<span class="number">1024</span>) &#123;</div><div class="line">		<span class="keyword">echo</span> <span class="string">"上传文件太大，请重新上传，页面正在跳转"</span>;</div><div class="line">		header(<span class="string">'refresh:10;url=upload.php'</span>);</div><div class="line">		<span class="keyword">exit</span>();</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="comment">//判断上传文件格式是否满足条件(暂未完善暂时只支持png与jpg格式图片)</span></div><div class="line">	$type = $_FILES[<span class="string">'file'</span>][<span class="string">'type'</span>];</div><div class="line">	<span class="comment">//echo $type;//通过该输出确认文件格式；</span></div><div class="line">	<span class="keyword">if</span> ($type!=<span class="string">'image/jpeg'</span>&amp;&amp;$type!=<span class="string">'image/png'</span>) &#123;</div><div class="line">		<span class="keyword">echo</span> <span class="string">"上传格式不对，请重新上传，页面正在跳转"</span>;</div><div class="line">		header(<span class="string">'refresh:3;url=upload.php'</span>);</div><div class="line">		<span class="keyword">exit</span>();</div><div class="line">	&#125;</div><div class="line">	<span class="comment">// 判断文件是否上传成功$_FILES['file']['tmp_name']代表临时文件 </span></div><div class="line">	<span class="keyword">if</span> (is_uploaded_file($_FILES[<span class="string">'file'</span>][<span class="string">'tmp_name'</span>])) &#123;</div><div class="line">		<span class="comment">// 把文件转存到希望的文件目录</span></div><div class="line">		$upload_file = $_FILES[<span class="string">'file'</span>][<span class="string">'tmp_name'</span>];</div><div class="line">		<span class="comment">//根据分类创建对应文件夹（应用于根据用户创建对应文件夹）</span></div><div class="line">		$user_path = $_SERVER[<span class="string">'DOCUMENT_ROOT'</span>].<span class="string">"upload/"</span>.$resource;</div><div class="line">		<span class="keyword">if</span> (!file_exists($user_path)) &#123;</div><div class="line">			mkdir($user_path,<span class="number">0777</span>,<span class="keyword">true</span>);</div><div class="line">		&#125;</div><div class="line">		<span class="comment">// 通过time()与rand()获取时间戳对文件重命名避免上传文件的重复而被覆盖</span></div><div class="line">		$move_file = $user_path.<span class="string">"/"</span>.time().rand(<span class="number">0</span>,<span class="number">100</span>).$_FILES[<span class="string">'file'</span>][<span class="string">'name'</span>];</div><div class="line">		<span class="comment">// 测试路径地址正确与否</span></div><div class="line">		<span class="comment">// echo $upload_file,'&lt;br&gt;';</span></div><div class="line">		<span class="comment">// echo $move_file;</span></div><div class="line">		<span class="comment">// 中文出错时转码函数iconv ('utf-8','gb2312',$move_file);</span></div><div class="line">		<span class="keyword">if</span> (move_uploaded_file($upload_file,$move_file)) &#123;</div><div class="line">			$sql = <span class="string">"insert into resource values(null,'$resource','$describe','$move_file')"</span>;</div><div class="line">			<span class="keyword">if</span> (mysql_query($sql)) &#123;</div><div class="line">				<span class="keyword">echo</span> <span class="string">'文件上传成功，正在跳转到下载页面...'</span>;</div><div class="line">				header(<span class="string">'refresh:3;url=download.php'</span>);</div><div class="line">			&#125;<span class="keyword">else</span>&#123;</div><div class="line">				mysql_query($sql) <span class="keyword">or</span> <span class="keyword">die</span>(mysql_error());</div><div class="line">			&#125;</div><div class="line">			</div><div class="line">		&#125;<span class="keyword">else</span>&#123;</div><div class="line">			<span class="keyword">echo</span> <span class="string">"文件上传失败,请上传文件..."</span>;</div><div class="line">			header(<span class="string">'refresh:3;url=upload.php'</span>);</div><div class="line">		&#125;	</div><div class="line">	&#125;<span class="keyword">else</span>&#123;</div><div class="line">		<span class="keyword">echo</span> <span class="string">"没有文件上传,请上传文件..."</span>;</div><div class="line">		header(<span class="string">'refresh:3;url=upload.php'</span>);</div><div class="line">	&#125;</div><div class="line">&#125;<span class="keyword">else</span>&#123;</div><div class="line">	<span class="keyword">echo</span> <span class="string">"未进行文件上传，正在跳转到上传页面..."</span>;</div><div class="line">	header(<span class="string">'refresh:3;url=upload.php'</span>);</div><div class="line">&#125;</div><div class="line"><span class="meta">?&gt;</span></div></pre></td></tr></table></figure>
<p>显示页面</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">&lt;?php </div><div class="line">require $_SERVER[&apos;DOCUMENT_ROOT&apos;].&apos;/inc/conn.php&apos;;</div><div class="line">$sql = &quot;select * from resource&quot;;</div><div class="line">$resource_content = mysql_query($sql);</div><div class="line"></div><div class="line">header(&apos;content-type:image/png&apos;);</div><div class="line">header(&apos;content-length:&apos;.filesize($filename));</div><div class="line">header(&apos;Content-Disposition: attachment; filename=&quot;1.png&quot;&apos;);</div><div class="line">readfile($filename);</div><div class="line">while ($resource = mysql_fetch_assoc($resource_content)) &#123;</div><div class="line">	echo &apos;&lt;h1&gt;文件分类:&apos;.$resource[&apos;resource&apos;].&apos;&lt;hr&gt;&apos;;</div><div class="line">	echo &apos;文件简介:&apos;.$resource[&apos;describe&apos;].&apos;&lt;br&gt;&apos;;</div><div class="line">	echo &apos;下载地址:&apos;.$resource[&apos;filename&apos;].&apos;&lt;br&gt;&lt;br&gt;&apos;;</div><div class="line">&#125;</div><div class="line">?&gt;</div></pre></td></tr></table></figure>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/6/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/6/">6</a><span class="page-number current">7</span><a class="page-number" href="/page/8/">8</a><span class="space">&hellip;</span><a class="page-number" href="/page/14/">14</a><a class="extend next" rel="next" href="/page/8/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel  sidebar-panel-active ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="uiste" />
          <p class="site-author-name" itemprop="name">uiste</p>
          <p class="site-description motion-element" itemprop="description">Stay Hungry，Stay Foolish</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">55</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/uiste" target="_blank" rel="external nofollow" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/uiste" target="_blank" rel="external nofollow" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/uiste" target="_blank" rel="external nofollow" title="知乎">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.uiste.com" title="uiste 个人博客" target="_blank">uiste 个人博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://uiste.github.io" title="uiste 技术博客" target="_blank">uiste 技术博客</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">uiste</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io" rel="external nofollow">Hexo</a> 趋势动力
</div>
<!--站长统计-->
<script src="https://s95.cnzz.com/z_stat.php?id=1259894121&web_id=1259894121" language="JavaScript"></script>
<!--<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next" rel="external nofollow">
    NexT.Mist
  </a>
</div> -->
&nbsp;&nbsp;&nbsp;本站总点击 <span id="busuanzi_value_site_pv"></span> 次
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;您是第 <span id="busuanzi_value_site_uv"></span> 位访客

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

<script>
(function(){
    var bp = document.createElement('script');
    bp.src = '//push.zhanzhang.baidu.com/push.js';
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"uiste"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/vendors/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
       search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();

    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
    'use strict';
    $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
            // get the contents from search data
            isfetched = true;
            $('.popup').detach().appendTo('.header-inner');
            var datas = $( "entry", xmlResponse ).map(function() {
                return {
                    title: $( "title", this ).text(),
                    content: $("content",this).text(),
                    url: $( "url" , this).text()
                };
            }).get();
            var $input = document.getElementById(search_id);
            var $resultContent = document.getElementById(content_id);
            $input.addEventListener('input', function(){
                var matchcounts = 0;
                var str='<ul class=\"search-result-list\">';
                var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                $resultContent.innerHTML = "";
                if (this.value.trim().length > 1) {
                // perform local searching
                datas.forEach(function(data) {
                    var isMatch = true;
                    var content_index = [];
                    var data_title = data.title.trim().toLowerCase();
                    var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                    var data_url = data.url;
                    var index_title = -1;
                    var index_content = -1;
                    var first_occur = -1;
                    // only match artiles with not empty titles and contents
                    if(data_title != '' && data_content != '') {
                        keywords.forEach(function(keyword, i) {
                            index_title = data_title.indexOf(keyword);
                            index_content = data_content.indexOf(keyword);
                            if( index_title < 0 && index_content < 0 ){
                                isMatch = false;
                            } else {
                                if (index_content < 0) {
                                    index_content = 0;
                                }
                                if (i == 0) {
                                    first_occur = index_content;
                                }
                            }
                        });
                    }
                    // show search results
                    if (isMatch) {
                        matchcounts += 1;
                        str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                        var content = data.content.trim().replace(/<[^>]+>/g,"");
                        if (first_occur >= 0) {
                            // cut out 100 characters
                            var start = first_occur - 20;
                            var end = first_occur + 80;
                            if(start < 0){
                                start = 0;
                            }
                            if(start == 0){
                                end = 50;
                            }
                            if(end > content.length){
                                end = content.length;
                            }
                            var match_content = content.substring(start, end);
                            // highlight all keywords
                            keywords.forEach(function(keyword){
                                var regS = new RegExp(keyword, "gi");
                                match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                            });

                            str += "<p class=\"search-result\">" + match_content +"...</p>"
                        }
                        str += "</li>";
                    }
                })};
                str += "</ul>";
                if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
                if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
                $resultContent.innerHTML = str;
            });
            proceedsearch();
        }
    });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };

    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

</body>
</html>
